<?php

require_once 'smarty_lib/Smarty.class.php';
require_once 'lib/DBClass.php';
require_once 'lib/Account.php';

require_once 'lib/bus.php';

$smarty = new Smarty();
$acc = new Account();

$bus = new bus();

$smarty->template_dir = 'template/';
$smarty->compile_dir = 'template_c/';

if(!$acc->validate_cookie()){
	$smarty->assign('error','Anda tidak mepunyai akses untuk membuka halaman ini');
	$smarty->display('login.html');
}else{


	$smarty->assign('data', $bus->getBus());
	$smarty->assign('cookie', $acc->get_cookie());
	$smarty->assign('page','bus.html');
	$smarty->assign('title','Update Bus');

	if (@$_GET['action'] == 'tambah') {
		$smarty->assign('page','tambahbus.html');
		$smarty->assign('title','Tambah Bus');
	}

	if(@$_POST['insert'] == 'submit'){
		$data = array(
			$_POST['No_bus'],
			$_POST['No_Polis'],
			$_POST['Nama_mesin'],
			$_POST['Nama_body'],
			$_POST['No_mesin'],
			$_POST['No_rangka'],
			$_POST['Kode_kelas'],
			$_POST['Keterangan']
			);
		$pel->TambahBus($data);
	} 

	if (@$_GET['action'] == 'edit') {
		$id = $_GET['id'];
		$edit = $bus->editbus($id);

		$smarty->assign('bus', $edit);
		$smarty->assign('title','Edit Bus');
		$smarty->assign('page', 'editbus.html');
	} 

	if (@$_GET['action'] == 'delete') {
		$id = $_GET['id'];
		$delete = $bus->hapusBus($id);
	}

	if (@$_POST['update'] == 'submit') {
		$data = array(
			$_POST['No_bus'],
			$_POST['No_Polis'],
			$_POST['Nama_mesin'],
			$_POST['Nama_body'],
			$_POST['No_mesin'],
			$_POST['No_rangka'],
			$_POST['Kode_kelas'],
			$_POST['Keterangan']
			);
		$pel->PostEdit($data);
	}
}
$smarty->display('dashboard.html');